package com.javabi.unix.line;

public abstract class LineNumberProcessor<R> implements ILineProcessor<R> {

	private int lineNumber = 0;

	public boolean processLine(String line) {
		if (trimLines()) {
			line = line.trim();
		}
		if (line.isEmpty()) {
			if (skipEmptyLines()) {
				return true;
			} else {
				return processEmptyLine(++lineNumber);
			}
		}
		return processLine(line, ++lineNumber);
	}

	public boolean processEmptyLine(int number) {
		return true;
	}

	protected boolean skipEmptyLines() {
		return false;
	}

	protected boolean trimLines() {
		return false;
	}

	public abstract boolean processLine(String line, int number);
}
